package com.aaa.java13;

import com.aaa.java11.StudentNew;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/16 14:55
 * @description：测试集合
 * @modified By：
 * @version: 1.0
 */
public class CollectionTest {
    public static void main(String[] args) {
/*        List<Integer> numbers= new ArrayList();
        numbers.add(23);
        numbers.add(32);
        numbers.add("aa");*/
        List list = new ArrayList();
        List listSon = new ArrayList();
        boolean zhangsan = list.add("zhangsan");
        System.out.println(zhangsan);
        list.add(20);
        list.add(true);
        listSon.add("儿子");
        listSon.add("儿媳妇");
        listSon.add("儿媳妇2");
        StudentNew studentNew = new StudentNew();
        studentNew.setName("张三");
        studentNew.setAge(80);
        listSon.add(studentNew);

        list.addAll(listSon);
        System.out.println(list.size());
      //  System.out.println(list.isEmpty());
        //遍历的第一种方式
        System.out.println("=============");
        for (Object o : list) {
            System.out.println(o.toString());
        }
        //遍历的第二种方式
        System.out.println("=============");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //遍历的第三种方式
        System.out.println("=============");
        //获取迭代器
        Iterator iterator = list.iterator();
        //hasNext()判断迭代器是否有值，有就返回true，没有返回false；
        while (iterator.hasNext()){
            //while禁止写多个next()
            //iterator.next();
            System.out.println(iterator.next());
        }


        System.out.println("----------------------------------");

/*        boolean b = list.contains("儿媳妇");
        System.out.println(b);*/

        StudentNew studentNew2 = new StudentNew();
        studentNew2.setName("张三");
        studentNew2.setAge(80);
        //contains，默认判断的是内存地址
        boolean contains = list.contains(studentNew);
        System.out.println(contains);
        boolean containsAll = list.containsAll(listSon);
        System.out.println("containsAll："+containsAll);


        System.out.println("+++++++++++++++++++++++++++++");
        List<Integer> numbers1= new ArrayList();
        numbers1.add(1);
        numbers1.add(2);
        numbers1.add(3);
        List<Integer> numbers2= new ArrayList();
        numbers2.add(3);
        numbers2.add(2);
        numbers2.add(4);
        boolean b = numbers1.retainAll(numbers2);
        System.out.println(b);
        System.out.println(numbers1);
        System.out.println(numbers2);
    }
}
